package com.ldf.jrtsp.enums;

import com.ldf.jrtsp.auth.IRtspAuth;
import com.ldf.jrtsp.auth.RtspBaseAuth;
import com.ldf.jrtsp.auth.RtspDigestAuth;
import com.ldf.jrtsp.auth.RtspNoneAuth;
import com.ldf.jrtsp.parser.RtspUrlParser;

/**
 * rtsp 认证类型
 *
 * @author lidaofu
 * @since 2024/6/19
 **/
public enum RtspAuthType implements IRtspAuth {

    /**
     * 不认证
     */
    NONE("",new RtspNoneAuth()),
    /**
     * basic认证
     */
    BASIC("Basic", new RtspBaseAuth()),

    /**
     * digest认证
     */
    DIGEST("Digest", new RtspDigestAuth());

    private final String value;

    private final IRtspAuth auth;

    RtspAuthType(String value, IRtspAuth auth) {
        this.value = value;
        this.auth = auth;
    }

    public String getValue() {
        return value;
    }

    /**
     * 根据认证信息获取认证类型
     *
     * @param authInfo
     * @return
     */
    public static RtspAuthType getRespAuthType(String authInfo) {
        if (authInfo.contains(RtspAuthType.BASIC.value)) {
            return RtspAuthType.BASIC;
        }
        return RtspAuthType.DIGEST;
    }

    @Override
    public String calcAuthInfo(RtspUrlParser rtspUrlParser, String authInfo,String method) {
        return auth.calcAuthInfo(rtspUrlParser, authInfo,method);
    }
}
